﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CayleyTree
{
	static class Draw
    {
		public static Graphics graphics;
		public static double th1 = 30 * Math.PI / 180;
		public static double th2 = 20 * Math.PI / 180;
		public static double per1 = 0.6;
		public static double per2 = 0.7;
		public static int n;
		public static double x0 = 300;
		public static double y0 = 300;
		public static double leng;

		public static void drawCayleyTree(int n, double x0, double y0, double leng, double th, int pen)
		{
			if (n == 0) return;

			double x1 = x0 + leng * Math.Cos(th);
			double y1 = y0 + leng * Math.Sin(th);

			drawLine(x0, y0, x1, y1, pen);

			drawCayleyTree(n - 1, x1, y1, per1 * leng, th + th1, pen);
			drawCayleyTree(n - 1, x1, y1, per2 * leng, th - th2, pen);
		}
		public static void drawLine(double x0, double y0, double x1, double y1, int pen)
		{
			graphics.DrawLine(
				pen == 0 ? Pens.Blue : (pen == 1 ? Pens.Black : Pens.Red),
				(int)x0, (int)y0, (int)x1, (int)y1);
		}
	}
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
	}
}
